package BinaryTree;

//二叉树的最小深度: https://leetcode.cn/problems/minimum-depth-of-binary-tree/description/
//时间复杂度: O(n)
public class MinHeight {
	//递归功能: 返回一颗树的最小深度
	//min(左侧最小深度,右侧最小深度)+1
	public int minDepth(TreeNode root) {
        if(root==null) return 0;
        if(root.left==null&&root.right==null) return 1;
        int ldeep=Integer.MAX_VALUE;
        int rdeep=Integer.MAX_VALUE;
        if(root.left!=null) {
        	ldeep=minDepth(root.left);
        }
        if(root.right!=null) {
        	rdeep=minDepth(root.right);
        }
        return 1+Math.min(ldeep,rdeep);
    }
}
